// 统一配置
$.ajaxPrefilter(function (options) {
  // 统一地址
  options.url = "http://ajax.frontend.itheima.net" + options.url;
  //判断里面是/my的加请求头以及验证token
  if (options.url.includes("/my/")) {
    // headers中,填写请求头
    options.headers = {
      Authorization: localStorage.getItem("token"),
    };
    options.complete = function (xhr) {
      if (
        xhr.responseJSON &&
        xhr.responseJSON.status === 1 &&
        xhr.responseJSON.message === "身份认证失败！"
      ) {
        localStorage.removeItem("token");
        location.href = "/login.html";
      }
    };
  }
});
